﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

/// <reference name="MicrosoftAjax.js" />

Type.registerNamespace("Microsoft.Live.ClientControls.VE.Extenders") ; 
Microsoft.Live.ClientControls.VE.Extenders.View3D = function(element) {
    /// <summary>
    ///   The Microsoft Live Server Controls VE Map View3D Extender client side code.
    /// </summary>
    /// <param name="element">The DOM element to have View3D event on click.</param>
    Microsoft.Live.ClientControls.VE.Extenders.View3D.initializeBase(this, [element]) ; 
    
    this._mode;
    this._altitude;
    this._heading;
    this._pitch;    
    this._mapControlID;
} 

Microsoft.Live.ClientControls.VE.Extenders.View3D.prototype = {

    initialize : function() {
        /// <summary>
        ///   Initialises the Extender.
        /// </summary>       
        Microsoft.Live.ClientControls.VE.Extenders.View3D.callBaseMethod(this, 'initialize');
        
        $addHandler(this.get_element(),"click", Function.createDelegate(this, this._onClick));
    }, 
    
    get_Mode : function() {
        return this._mode;
    }, 

    set_Mode : function(value) {
        this._mode = value;
    },   
    
    get_Altitude : function() {
        return this._altitude;
    }, 

    set_Altitude : function(value) {
        this._altitude = value;
    },  
    
    get_Heading : function() {
        return this._heading;
    }, 

    set_Heading : function(value) {
        this._heading = value;
    }, 
    
    get_Pitch : function() {
        return this._pitch;
    }, 

    set_Pitch : function(value) {
        this._pitch = value;
    },        
    
    get_MapControlID : function() {
        return this._mapControlID;
    }, 

    set_MapControlID : function(value) {
        this._mapControlID = value;
    },        
    
    _onClick : function(e) {
        //Get the map control and View3D
        var mapcontrol = $find(this._mapControlID);
        if (mapcontrol) {
            switch (this._mode) {
                //Altitude
                case 1:
                    mapcontrol.set_Altitude(this._altitude);
                    break;
                //Heading
                case 2:
                    mapcontrol.set_Heading(this._heading);
                    break;
                //AltitudeHeading
                case 3:
                    mapcontrol.set_Altitude(this._altitude);
                    mapcontrol.set_Heading(this._heading);
                    break;
                //Pitch
                case 4:
                    mapcontrol.set_Pitch(this._pitch);
                    break;
                //AltitudePitch
                case 5:
                    mapcontrol.set_Altitude(this._altitude);
                    mapcontrol.set_Pitch(this._pitch);
                    break;
                //HeadingPitch
                case 6:
                    mapcontrol.set_Heading(this._heading);
                    mapcontrol.set_Pitch(this._pitch);
                    break;
                //AltitudeHeadingPitch
                case 7:
                    mapcontrol.set_Altitude(this._altitude);
                    mapcontrol.set_Heading(this._heading);
                    mapcontrol.set_Pitch(this._pitch);
                    break;                                       
            } 
        }
        //Don't want the page to post back, so prevent default action of control
        e.preventDefault();
    },
    
    dispose : function() {
        /// <summary>
        ///   Dispose all events and objects.
        /// </summary>     
        $clearHandlers(this.get_element());
        Microsoft.Live.ClientControls.VE.Extenders.View3D.callBaseMethod(this, 'dispose');
    }
} 

Microsoft.Live.ClientControls.VE.Extenders.View3D.registerClass("Microsoft.Live.ClientControls.VE.Extenders.View3D", Sys.UI.Behavior) ;

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();